package com.thirtywords.cleaner;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class HandyCleaner extends Cleaner {

	public HandyCleaner(String url) {
		super(url, 0);
	}

	@Override
	public String doClean() {

		System.out.println(">>>>>>>>>>>>>>>" + code.getUrl());
		SimpleDateFormat s = new SimpleDateFormat("HH:mm:ss.SSS");
		Date d;

		d = new Date();
		System.out.println(s.format(d));
		System.out.println("Orginal " + code.getOriginalCode().length());

		String body = getBody(code.getOriginalCode());

		d = new Date();
		System.out.println(s.format(d));
		System.out.println("Body " + body.length());

		d = new Date();
		System.out.println(s.format(d));

		StringBuilder builder = new StringBuilder();		
		if (body != null) {

			String result=removeAttributes(body);
			System.out.println("Result " + result.length());

			builder.append(result);
		}
		d = new Date();
		System.out.println(s.format(d));
		
		System.out.println(">>>>>>>>>>>>>>><<<<<<<<<<<<<<<<<<<<<<");

		try {

			FileWriter fstream = new FileWriter("c:/workspace/out.txt"); 
			BufferedWriter out = new BufferedWriter(fstream);
			out.write(builder.toString());
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}finally{
		}

		return builder.toString();
	}
}
